#include "Sender.h"
#include "utils.hpp"

using namespace sw::redis;

bool RedisSender::Send(const cv::Mat& frame, const std::string& taskId, int number)
{
	std::vector<uchar> buf;
	std::vector<char> data;
	cv::imencode(".jpg", frame, buf);
	base64_encode(buf, data);
	
	if (currentTaskId != taskId) {
		redis.rpush(rootKey, taskId);
		currentTaskId = taskId;
	}
	
	char keybuf[2048];
	sprintf(keybuf, "%s-%04d", taskId.c_str(), number);
	std::string imagKey(keybuf);
	redis.rpush(taskId, imagKey);
	redis.set(imagKey, std::string(data.begin(), data.end()));
	
	return true;
}
